package videoExercises;

public class StudentGarde implements Comparable<StudentGarde> {
    private String name;
    private int age;
    private int chineseGarde;
    private int mathGarde;
    private int englishGarde;
    public StudentGarde(){}
    public StudentGarde(String name, int age, int chineseGarde ,int mathGarde ,int englishGarde){
        this.name=name;
        this.age=age;
        this.chineseGarde=chineseGarde;
        this.mathGarde=mathGarde;
        this.englishGarde=englishGarde;
    }

    public String getName() {
        return name;

    }
    public void setName(String name) {
        this.name = name;
    }
    public int getAge() {
        return age;
    }
    public void setAge(int age) {
        this.age = age;
    }
    public int getChineseGarde() {
        return chineseGarde;
    }
    public void setChineseGarde(int chineseGarde) {
        this.chineseGarde = chineseGarde;
    }
    public int getMathGarde() {
        return mathGarde;
    }
    public void setMathGarde(int mathGarde) {
        this.mathGarde = mathGarde;
    }
    public int getEnglishGarde() {
        return englishGarde;
    }
    public void setEnglishGarde(int englishGarde) {
        this.englishGarde = englishGarde;
    }
    public int sum(){
        return this.chineseGarde+this.mathGarde+this.englishGarde;
    }
    public String toString(){
        //int sum =0;
        //sum=sum+chineseGarde+mathGarde+englishGarde;
        return "StudentGarde{" +
                "name='" + name + '\'' + ", age=" + age + ", chineseGarde=" + chineseGarde + ", mathGarde=" + mathGarde + ", englishGarde=" + englishGarde +", sumGarde="+ sum()+'}';
    }

    @Override
    public int compareTo(StudentGarde o) {
        int sum1 = this.chineseGarde + this.mathGarde + this.englishGarde;
        int sum2 =o.chineseGarde + o.mathGarde + o.englishGarde;
        int i =sum1-sum2;
         i = i == 0 ? this.getChineseGarde() - o.getChineseGarde() : i;
        i = i == 0 ? this.getMathGarde() - o.getMathGarde() : i;
        i = i == 0? this.getEnglishGarde() - o.getEnglishGarde() : i;
        i=i==0?this.getAge()-o.getAge():i;
        i=i==0?this.getName().compareTo(o.getName()):i;
        return i;
    }
}


